home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
dm3_src.zip
/
DMIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-02
|
90KB
|
2,430 lines
/* ************************************************************************* */
/* */
/* D O O R W A R E I / O L I B R A R Y */
/* */
/* For Mycrosoft C */
/* */
/* ************************************************************************* */
/* */
/* This module contains functions used to input and output info */
/* with the user and remote_users console. Additionally, it */
/* contains functions that interface with DOS. */
/* */
/* The following funtions are contained in this file: */
/* */
/* io_open - Determine remote port number */
/* io_reopen - ReAquire comm port resources */
/* io_close - Release comm port resources */
/* */
/* modem_carrier - Test for carrier detect */
/* modem_status - Test for remote char available */
/* modem_input - Read char from comm port */
/* modem_output - Write char to comm port */
/* modem_wait - Wait for output to complete */
/* modem_iflush - Flush input buffer */
/* modem_oflush - Flush output buffer */
/* */
/* local_status - Test for local char available */
/* local_input - Read char from keyboard */
/* local_cls - Clear the local display */
/* local_output - Write char to local display */
/* local_print - Write a string to local display */
/* local_wait - Wait for output to complete */
/* local_iflush - Flush input buffer */
/* local_oflush - Flush output buffer */
/* get_local_cursor- Get the current local cursor position */
/* set_local_cursor- Set the current local cursor position */
/* set_local_banner- Set the banner */
/* put_local_banner- Write banner to display */
/* */
/* io_status - Test for char available */
/* io_input - Read char */
/* io_linput - Read line with line feed */
/* io_lxinput - Read line without line feed */
/* io_lexinput - Read line without an echo */
/* tio_input - Read char (timed) */
/* tio_linput - Read line with line feed (timed) */
/* tio_lxinput - Read line without line feed (timed) */
/* io_pause - Wait for a carriage return */
/* io_output - Write char */
/* io_loutput - Write line */
/* io_wait - Wait for output to complete */
/* io_iflush - Flush input buffer */
/* io_oflush - Flush output buffer */
/* */
/* no_cursor - Turn off local cursor */
/* small_cursor - Set small local cursor */
/* medium_cursor - Set medium local cursor */
/* large_cursor - Set large local cursor */
/* */
/* */
/* ************************************************************************* */
/* ************************************************************************* */
/* PROGRAM HISTORY */
/* ************************************************************************* */
/* 06/20/87 Version 1.00 */
/* 01/01/90 Version 3.00 */
/* */
/* */
/* */
/* ************************************************************************* */
#include "dmcfg.h" /* Std. defines & includes */
#include "dmdata.h" /* Std DM storage */
/*
*
* Test environment control
*
* Set to 0 for standard version
* Set to 1 for test version
*
*/
#define TEST_VERSION 0
/*
*
* Structure definitions
*
*/
struct dmport_cfg
{
int defined; /* Defined flags */
/* 0 = Not defined */
/* 1 = Default definition */
/* 2 = Defined by config file */
unsigned int address; /* Comm Port base address */
unsigned int irq_id; /* Interrupt request number */
int int_enable; /* Interrupt enable flag */
/* 0 = BIOS/Fossil I/O */
/* 1 = Direct I/O */
/* 2 = Interrupt I/O */
int handshake; /* Handshake flag */
/* 0 = No handshaking */
/* 1 = XON/XOFF handshaking */
/* 2 = RTS/CTS handshaking */
/* 3 = Both 1 & 2 */
int passthru; /* Passthrough flag */
/* 0 = No passthrough (Do RETI) */
/* 1 = Pass int to original vector */
};
/*
*
* Local module storage
*
*/
static struct dmport_cfg dmio_ports[8] = /* I/O port definitions */
{ 1, 0x3f8, 4, 2, 2, 0,
1, 0x2f8, 3, 2, 2, 0,
1, 0x3e8, 4, 2, 2, 0,
1, 0x2e8, 3, 2, 2, 0,
0, 0x000, 0, 0, 0, 0,
0, 0x000, 0, 0, 0, 0,
0, 0x000, 0, 0, 0, 0,
0, 0x000, 0, 0, 0, 0 };
static int remote_port = 0;
static int io_init_state = 0;
static int io_open_state = 0;
static char cls[5] = {"\033[2J"};
static char eol[5] = {"\033[K"};
static long mark_time;
static long mark_time2;
static long tick_time;
static int chat_flag = 0;
static int local_line_no = 24;
static char banner_msg[81] = {" "};
static char banner_color;
/******************************************************************************
*
* IO_OPEN - Open I/O channel(s)
*
* process 1. If no parameters, disable remote
* 2. Open node file
* 3. Read in port configurations if present
* 4. Initialize comm port i/o
* 5. Exit
* input Node = -1 if no parameters
* Else node = BBS node number
* output Returns 0 if all ok
* Returns -1 if can't open node file NODES.BBS
* Returns -2 if illegal node number in NODES.BBS
* Returns -3 if illegal port name in NODES.BBS
* Returns -4 if illegal number of parameters in PORTS.BBS
* Returns -5 if illegal comm port id in PORTS.BBS
* Returns -6 if illegal comm port address in PORTS.BBS
* Returns -7 if illegal IRQ number in PORTS.BBS
* Returns -8 if illegal INT enable in PORTS.BBS
* Returns -9 if illegal handshake in PORTS.BBS
* Returns -10 if illegal passthrough in PORTS.BBS
* Returns -11 if Duplicate comm port definition in PORTS.BBS
* Returns -12 if No defined port ids in PORTS.BBS
* Returns -13 if Port is not defined in PORTS.BBS
*****************************************************************************/
io_open(node)
{
#if COMPILER == MSC
onexit_t onexit(); /* Onexit declaration */
#endif
#if COMPILER == BTC
int atexit();
#endif
void io_close();
FS rfd; /* File descriptor */
int i, j, k; /* Work variables */
char fname[80]; /* File name */
if(node == -1) /* If not remote... */
{
remote_user = 0; /* ...then disable it */
remote_port = 0;
}
else
{
bbs_node_info.snoop[1] = '1'; /* Force on temporarily */
strcpy(rfd.name, bbs_dir); /* Build filename */
strcat(rfd.name, "NODES.BBS"); /* Open node file */
i = file_open(&rfd, FREAD, FTEXT, FNOCREATE); /* Open node file */
if(i) /* If file not there... */
return(-1); /* ...error */
i = 0; /* Set states */
j = 1;
if(node == 0)
k = 1;
else
k = node;
while((i < k) & (j != 0)) /* Do until at right rec... */
{
if(fgets(dminbuff, 255, rfd.fd)) /* ...if all ok... */
i++; /* ......continue */
else
j = 0; /* ...else past eof */
}
file_close(&rfd); /* Close the file */
if(j == 0) /* If at eof... */
return(-2); /* ...error */
i = 0; /* Init index */
while((dminbuff[i] != 0x0d) && /* Do until end of line... */
(dminbuff[i] != 0x0a) &&
(dminbuff[i] != ' ') &&
(dminbuff[i] != 0x09) &&
(dminbuff[i] != 0x1a) &&
(dminbuff[i] != 0x00))
{
fname[i] = dminbuff[i]; /* ...store the character */
i++; /* ...adjust index */
}
fname[i] = '\0'; /* Terminate the string */
remote_user = atoi(&(fname[i - 1])); /* Get comm port number */
remote_port = remote_user;
if(((remote_user == 0) && (strnicmp(fname, "COM0", 4) != 0)) ||
(strnicmp(fname, "COM", 3) != 0))
return(-3); /* Error if bad device */
if(remote_user) /* If remote active... */
{
i = dmread_ports(); /* ...then read port info */
if(i) /* ...If an error */
return(i - 2); /* ......then return it */
else
{
if(dmio_ports[remote_user - 1].defined == 0)
return(-13);
dmcomm_init(remote_user - 1,
dmio_ports[remote_user - 1].address,
dmio_ports[remote_user - 1].irq_id,
dmio_ports[remote_user - 1].int_enable,
dmio_ports[remote_user - 1].handshake,
dmio_ports[remote_user - 1].passthru);
if(io_init_state == 0)
{
#if COMPILER == MSC
onexit(io_close);
#endif
#if COMPILER == BTC
atexit(io_close);
#endif
io_init_state = 1;
}
io_open_state = 1;
}
}
}
return(0); /* ...all is ok */
}
/******************************************************************************
*
* IO_REOPEN - ReOpen I/O channel(s)
*
* process 1. If no parameters, disable remote
* 2. Initialize comm port i/o
* 3. Exit
* input Node = -1 if no parameters
* Else node = BBS node number
* output Returns 0 if all ok
*****************************************************************************/
io_reopen()
{
remote_user = remote_port;
if(remote_user) /* If remote only... */
{
if(io_open_state == 0)
{
dmcomm_init(remote_user - 1,
dmio_ports[remote_user - 1].address,
dmio_ports[remote_user - 1].irq_id,
dmio_ports[remote_user - 1].int_enable,
dmio_ports[remote_user - 1].handshake,
dmio_ports[remote_user - 1].passthru);
io_open_state = 1;
}
}
return(0); /* ...all is ok */
}
/******************************************************************************
*
* IO_CLOSE - Release I/O resources
*
* process 1. If local, exit
* 2. Release resources
* 3. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
void io_close()
{
/*
* Release if in use
*/
if(io_open_state)
{
dmcomm_wait(); /* ...ten wait for i/o done */
dmcomm_release(); /* ...and release resources */
}
io_open_state = 0;
remote_user = 0;
return; /* Always return 0 */
}
/******************************************************************************
*
* MODEM_CARRIER - Test for carrier detect
*
* process 1. Pretend all ok if remote is not active
* 2. Test modem status via BIOS
* 3. Return status info
* input Uses remote user data values
* output Returns 0 if remote_user is inactive
* Returns 0 if carrier is still active
* Returns 1 if carrier dropped
*****************************************************************************/
modem_carrier()
{
#if TEST_VERSION
return(0); /* always return 0 if test */
#endif
if(remote_user == 0) /* If line not in use... */
return(0); /* ...pretend all is ok */
if((dmcomm_regs() & 0x80) != 0) /* Test carrier detect */
return(0); /* All ok here */
else
return(1); /* Ooops, lost carrier */
}
/******************************************************************************
*
* MODEM_STATUS - Test for remote char available
*
* process 1. Return no data if remote is not active
* 2. Read status infor from BIOS
* 3. Return input status
* input Uses remote user data values
* output Returns 0 if remote user is inactive
* Returns 0 if no remote char present
* Returns 2 if remote char is available
*****************************************************************************/
modem_status()
{
#if TEST_VERSION
return(0); /* always return 0 if test */
#endif
if(remote_user == 0) /* If line not in use... */
return(0); /* ...then no key pressed */
if(dmcomm_status() == 1) /* Test key pressed */
return(2); /* ... key pressed */
else
return(0); /* ... no key */
}
/******************************************************************************
*
* MODEM_INPUT - Read a remote chararcter
*
* process 1. Read data via BIOS
* 2. Mask it to ASCII
* 3. Return data
* input Uses remote user data values
* output Returns 0 if remote_user is inactive
* Returns character
*****************************************************************************/
modem_input()
{
int c;
#if TEST_VERSION
return(0); /* always return 0 if test */
#endif
c = dmcomm_input(); /* Execute */
if(c == -1) /* ...if loss of carrier */
return(0); /* ...then return null */
return(c & 0x7f); /* Return data */
}
/******************************************************************************
*
* MODEM_OUTPUT - Write a remote character
*
* process 1. Ignore if remote inactive
* 2. Write remote data via BIOS
* 3. Test if line feed
* 4. Return no error if not
* 5. Output nulls
* 6. Return no error
* input Uses remote user data values
* Data to output
* output Returns 0
*****************************************************************************/
modem_output(data)
int data; /* Data to output */
{
int i; /* Work variable */
#if TEST_VERSION
return(0); /* no output if test version */
#endif
if(remote_user) /* Only if remote active... */
{
if(modem_carrier()) /* Ignore if no carrier */
return(-1);
dmcomm_output(data); /* Execute */
if(data == '\n') /* If it is a line feed... */
{
for(i = 0 ; i < user_nulls ; i++) /* ... send his nulls */
dmcomm_output(0);
}
}
return(0); /* No errors */
}
/******************************************************************************
*
* MODEM_WAIT - Wait for modem output to complete
*
* process 1. If local, exit
* 2. Wait for TX buffer empty
* 3. Exit
* input None
* output Returns AX = -1 if no carrier
* Returns AX = 0 if TX buffer empty
* Returns AX = 1 if timeout
*****************************************************************************/
modem_wait()
{
/*
* Wait if in use
*/
if(remote_user) /* If remote active... */
return(dmcomm_wait()); /* ...then wait for complete */
}
/******************************************************************************
*
* MODEM_IFLUSH - Purge all input
*
* process 1. If local, exit
* 2. Clear the buffers
* 3. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
modem_iflush()
{
/*
* Flush buffers if in use
*/
if(remote_user) /* If remote active... */
dmcomm_iflush(); /* ...then flush input */
return(0); /* Always returns 0 */
}
/******************************************************************************
*
* MODEM_OFLUSH - Purge all output
*
* process 1. If local, exit
* 2. Clear the buffers
* 3. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
modem_oflush()
{
/*
* Flush buffers if in use
*/
if(remote_user) /* If remote active... */
dmcomm_oflush(); /* ...then flush input */
return(0); /* Always returns 0 */
}
/******************************************************************************
*
* LOCAL_STATUS - Test for local char available
*
* process 1. Read the status
* 2. Return input status
* input none
* output Returns 0 if no local char present
* Returns 1 if local char is available
*****************************************************************************/
local_status()
{
if(kbhit()) /* Test local status */
return(1); /* Local data available */
else
return(0); /* No local data available */
}
/******************************************************************************
*
* LOCAL_INPUT - Read a local chararcter
*
* process 1. Read data via BIOS
* 2. Mask it to ASCII
* 3. Return data
* input Uses remote user data values
* output Returns character
*****************************************************************************/
local_input()
{
long cur_time(); /* Get current time */
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
long time_val; /* Current time value */
int key; /* Keyboard character */
char msg[32]; /* Work buffer */
inregs.x.ax = (0x0000); /* Function number */
int86x(0x16, &inregs, &outregs, &segregs); /* Execute */
key = outregs.x.ax; /* Set to ASCII data */
/* Test for SysOp Keys */
if(remote_user)
{
/* Test for ANY toggle */
if(key == 0x3e00)
{
if(bbs_node_info.sysop_annoy[1] == '1')
{
local_print("\r\nSysOp annoy disabled...\r\n");
bbs_node_info.sysop_annoy[1] = '0';
}
else
{
local_print("\r\nSysOp annoy enabled...\r\n");
bbs_node_info.sysop_annoy[1] = '1';
}
return(0); /* Exit NULL character */
}
/* Test for AVL toggle */
if(key == 0x4000)
{
if(bbs_node_info.sysop_avail[1] == '1')
{
local_print("\r\nSysOp avail disabled...\r\n");
bbs_node_info.sysop_avail[1] = '0';
}
else
{
local_print("\r\nSysOp avail enabled...\r\n");
bbs_node_info.sysop_avail[1] = '1';
}
return(0); /* Exit NULL character */
}
/* Test for Snoop toggle */
if(key == 0x4300)
{
if(bbs_node_info.snoop[1] == '1')
{
local_print("\r\nSysOp snoop disabled...\r\n");
local_cls();
no_cursor();
bbs_node_info.snoop[1] = '0';
}
else
{
local_print("\r\nSysOp snoop enabled...\r\n");
put_local_banner();
small_cursor();
bbs_node_info.snoop[1] = '1';
}
return(0); /* Exit NULL character */
}
/* Test for Controls */
if(key == 0x6800)
{
local_print("\rUser aborted...\r\n");
user_signoff = cur_time();
key = 0;
}
else if(key == 0x4d00)
{
user_signoff += 60L;
time_val = cur_time();
if(time_val < user_signon)
time_val += DAY_SECONDS;
sprintf(msg, "\rUser time = %ld [%ld].\r\n", (user_signoff - time_val) / 60L, (user_signoff - user_signon) / 60L);
local_print(msg);
key = 0;
}
else if(key == 0x4b00)
{
user_signoff -= 60L;
sprintf(msg, "\rUser time = %ld...\r\n", (user_signoff - user_signon) / 60L);
local_print(msg);
key = 0;
}
/* Test for CHAT */
if((key == 0x4400) && (chat_flag == 0))
{
print_string("\r\nHi this is your SysOp. Sorry to break in and chat...\r\n");
chat_flag = 1; /* Set chat active */
chat_mode();
chat_flag = 0; /* Set chat inactive */
return(0); /* Exit NULL character */
}
}
return(key & 0x7f); /* Return character */
}
/******************************************************************************
*
* LOCAL_CLS - Clear local dislay
*
* process 1. Send command to BIOS
* 2. Exit
* input None
* output None
*****************************************************************************/
local_cls()
{
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
int key; /* Keyboard character */
inregs.h.ah = (0x06); /* Function number to scroll */
inregs.h.al = (0x00); /* Set to clear display */
inregs.h.bh = (0x07); /* Attribute for filler */
inregs.h.bl = (0x00); /* Page to scroll */
inregs.h.cl = (0x00); /* Top left of window */
inregs.h.ch = (0x00);
inregs.h.dl = (0x4f); /* Bottom right of window */
inregs.h.dh = (0x18);
int86x(0x10, &inregs, &outregs, &segregs); /* Execute */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* LOCAL_BELL - Beep local console
*
* process 1. Write the data
* 2. Exit no error
* input None
* output Returns 0
*****************************************************************************/
local_bell()
{
putchar('\007'); /* Send to local console */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* LOCAL_OUTPUT - Write a local character
*
* process 1. Write the data
* 2. Test for line feed
* 3. Exit no error if not
* 4. Test for past line 23
* 5. Exit no error if not
* 6. Scroll the screen
* 7. Get current cursor position
* 8. Back up one line
* 9. Set new cursor position
* 10. Exit no error
* input Data to output
* output Returns 0
*****************************************************************************/
local_output(data)
int data; /* Data to output */
{
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
int x, y; /* Cursor position */
if((remote_user == 0) || (bbs_node_info.snoop[1] == '1'))
{
if((remote_user == 0) || (data != '\007'))
putchar(data); /* Send to local console */
if(data == '\n') /* If going to a new line... */
{
local_line_no++; /* ...Bump line number */
if(local_line_no > 23) /* ...If at bottom... */
{
get_local_cursor(&x, &y); /* Get current position */
inregs.h.ah = (0x06); /* Function number to scroll */
inregs.h.al = (0x01); /* Lines to scroll */
inregs.h.bh = (0x07); /* Attribute for filler */
inregs.h.bl = (0x00); /* Page to scroll */
inregs.h.cl = (0x00); /* Top left of window */
inregs.h.ch = (0x00);
inregs.h.dl = (0x4f); /* Bottom right of window */
inregs.h.dh = (0x17);
int86x(0x10, &inregs, &outregs, &segregs); /* Execute */
/* set_local_cursor(x, 23); */ /* Set new position */
set_local_cursor(0, 23); /* Set new position */
local_line_no = 23; /* ......set it back */
}
}
}
return(0); /* Exit no errors */
}
/******************************************************************************
*
* LOCAL_PRINT - Print string locally
*
* process 1. Print a char
* 2. Exit if done
* 3. Next char
* 4. Goto 1
* input Pointer to string
* output Returns 0
*****************************************************************************/
local_print(string)
char *string; /* String to print */
{
int i;
for(i = 0 ; i < strlen(string) ; i++)
local_output(string[i]);
return(0);
}
/******************************************************************************
*
* LOCAL_WAIT - Wait for output to complete (provided only for balance)
*
* process 1. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
local_wait()
{
/*
* Provided only for balance
*/
return(0); /* Exit, nothing to do */
}
/******************************************************************************
*
* LOCAL_IFLUSH - Purge all input
*
* process 1. If no chars then goto 3
* 2. Input char & goto 1
* 3. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
local_iflush()
{
int st;
/*
* Flush all input
*/
st = 1;
while(st) /* Do until nothing left */
{
if(local_status()) /* If chars available... */
local_input(); /* ...then flush input */
else /* Otherwise... */
st = 0; /* ...all done */
}
return(0); /* Always returns 0 */
}
/******************************************************************************
*
* LOCAL_OFLUSH - Purge all output (Provided only for balance)
*
* process 1. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
local_oflush()
{
/*
* Provided only for balance
*/
return(0); /* Always returns 0 */
}
/******************************************************************************
*
* GET_LOCAL_CURSOR - Get current local cursor position
*
* process 1. Make BIOS call
* 2. Return data
* input Pointer to return parms
* output Returns 0
*****************************************************************************/
get_local_cursor(xpos, ypos)
int *xpos; /* Pointer to x position */
int *ypos; /* Pointer to y position */
{
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
inregs.x.ax = (0x0300); /* Function number */
int86x(0x10, &inregs, &outregs, &segregs); /* Execute */
*xpos = outregs.h.dl; /* Return the parms */
*ypos = outregs.h.dh;
return(0); /* Exit no errors */
}
/******************************************************************************
*
* SET_LOCAL_CURSOR - Set current local cursor position
*
* process 1. Make BIOS call
* 2. Return
* input X & Y positions
* output Returns 0
*****************************************************************************/
set_local_cursor(xpos, ypos)
int xpos; /* x position */
int ypos; /* y position */
{
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
inregs.x.ax = (0x0200); /* Function number */
inregs.x.bx = (0x0000); /* Page number */
inregs.h.dl = xpos; /* Position to go to */
inregs.h.dh = ypos;
int86x(0x10, &inregs, &outregs, &segregs); /* Execute */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* SET_LOCAL_BANNER - Setup local banner line
*
* process 1. Store in local char array
* 2. Return
* input Pointer to banner message
* output Returns 0
*****************************************************************************/
set_local_banner(string, foreground, background)
char *string; /* Banner message */
{
strcpy(banner_msg, string); /* Copy it over */
banner_color = (background << 4) + foreground;
return(0); /* Exit no errors */
}
/******************************************************************************
*
* PUT_LOCAL_BANNER - Write local banner line to screen
*
* process 1. Save current cursor position
* 2. Set cursor to line 25
* 3. Write the banner
* 4. Reset cursor back to its position
* 5. Return no error
* input None
* output Returns 0
*****************************************************************************/
put_local_banner()
{
union REGS inregs, outregs; /* BIOS access structures */
struct SREGS segregs;
int x, y; /* Cursor position */
int i; /* Loop variable */
if((remote_user == 0) || (bbs_node_info.snoop[1] == '1'))
{
get_local_cursor(&x, &y); /* Save current location */
for(i = 0 ; i < 80 ; i++) /* Copy the line */
{
set_local_cursor(i, 24); /* Set location to print */
inregs.h.ah = (0x09); /* Function number */
inregs.h.al = banner_msg[i]; /* Function number */
inregs.h.bh = (0x00); /* Page number */
inregs.h.bl = banner_color; /* Color attributes */
inregs.x.cx = (0x0001); /* Output count */
int86x(0x10, &inregs, &outregs, &segregs); /* Execute */
}
if(y > 23) /* If we are too low... */
y = 23; /* ...then backup */
set_local_cursor(x, y); /* Restore cursor position */
}
return(0); /* Exit no errors */
}
/******************************************************************************
*
* IO_STATUS - Test for char available
*
* process 1. Test local status
* 2. Return true if local ready
* 3. Test remote status
* 4. Return true if remote ready
* 4. Return false
* input none
* output Returns 0 if no char present
* Returns 1 if local char is available
* Returns 2 if remote char is available
*****************************************************************************/
io_status()
{
if(local_status()) /* Test local console */
return(1); /* exit if key pressed */
if(modem_status()) /* Test remote console */
return(2); /* exit if key pressed */
return(0); /* else no key */
}
/******************************************************************************
*
* IO_TESTS - Test time & line controls
*
* process 1. Test carrier detect
* 2. Return -1 if carrier dropped
* 3. Test for no activity
* 4. Return -2 if no activity
* 5. Return -2 if no activity
* 6. Test for time limit exceeded
* 7. Return -3 if less than 2 minutes
* 8. Return -4 if time limit exceeded
* 9. Return 0 (all ok)
* input none
* output Returns -1 if carrier dropped
* Returns -2 if no remote activity
* Returns -3 if less than 2 minutes remaining
* Returns -4 if no time remaining
* Returns 0 if no errors
*****************************************************************************/
io_tests()
{
long cur_time(); /* Get current time decl */
long check_time; /* Cur time storage */
int stat; /* Input status variable */
mark_time = cur_time(); /* Flag current time */
if(modem_carrier()) /* If carrier dropped... */
return(-1); /* ...exit with error */
check_time = cur_time(); /* Check current time */
if(check_time < mark_time) /* If we wrapped past 12... */
check_time += DAY_SECONDS; /* ...adjust it */
if(check_time > (mark_time + 180L)) /* If it has been 3 mins... */
return(-2); /* ...exit with error */
stat = test_timeout(); /* Test remote time access */
if(stat == -1) /* If time warning msg... */
return(-3); /* ...exit with warning */
if(stat == -2) /* If time exceeded... */
return(-4); /* ...exit with error */
return(0); /* all is ok */
}
/******************************************************************************
*
* IO_INPUT - Input character
*
* process 1. Test carrier detect
* 2. Return -1 if carrier dropped
* 3. Test for no activity
* 4. Return -2 if no activity
* 5. Return -2 if no activity
* 6. Test for time limit exceeded
* 7. Return -3 if less than 2 minutes
* 8. Return -4 if time limit exceeded
* 9. Test for character ready
* 10. Goto 1 if no data available
* 11. Process local if local ready
* 12. Process remote if remote ready
* 13. Return character
* input none
* output Returns -1 if carrier dropped
* Returns -2 if no remote activity
* Returns -3 if less than 2 minutes remaining
* Returns -4 if no time remaining
* Returns chararcter
*****************************************************************************/
io_input()
{
long cur_time(); /* Get current time decl */
long check_time; /* Cur time storage */
int stat; /* Input status variable */
mark_time = cur_time(); /* Flag current time */
while(1) /* Do until we get something */
{
if(modem_carrier()) /* If carrier dropped... */
return(-1); /* ...exit with error */
check_time = cur_time(); /* Check current time */
if(check_time < mark_time) /* If we wrapped past 12... */
check_time += DAY_SECONDS; /* ...adjust it */
if(check_time > (mark_time + 180L)) /* If it has been 3 mins... */
return(-2); /* ...exit with error */
stat = test_timeout(); /* Test remote time access */
if(stat == -1) /* If time warning msg... */
return(-3); /* ...exit with warning */
if(stat == -2) /* If time exceeded... */
return(-4); /* ...exit with error */
stat = io_status(); /* Test if char available */
if(stat == 1) /* If keyboard char... */
return(local_input()); /* ...return it */
if(stat == 2) /* If remote char... */
{
stat = modem_input(); /* ...return it */
if(stat)
return(stat);
}
}
}
/******************************************************************************
*
* IO_LINPUT - Input line with line feed
*
* process 1. Read a line
* 2. Print a crlf sequence
* 3. Return 0
* input Pointer to buffer
* output Returns 0
*****************************************************************************/
io_linput(buffer)
char *buffer; /* Buffer to store input in */
{
io_lxinput(buffer); /* Read a line */
print_string("\r\n"); /* Echo a new line */
return(0); /* Exit no error */
}
/******************************************************************************
*
* IO_LXINPUT - Input line without line feed
*
* process 1. Read a caharcter
* 2. If -1 return ~NO_CARRIER
* 3. If -2 return ~NOT_ACTIVE
* 4. If -3 return ~TIME_WARNING
* 5. If -4 return ~TIMEOUT
* 6. If cr then teminate input
* 7. If bs then print bs/space/bs
* 8. Ignore if buffer if full
* 9. Ignore if less than 20H and goto 1
* 10. Store character
* 11. Echo to output
* 12. Goto 1
* input Pointer to buffer
* output Returns 0
*****************************************************************************/
io_lxinput(buffer)
char *buffer; /* Buffer to store chars in */
{
int count = 0; /* Character counter */
int key; /* Character input variable */
int max = 80; /* Max buffer size */
while(1) /* Repeat till done... */
{
key = io_input(); /* Get a character */
if(key == -1) /* If carrier dropped... */
{
strcpy(buffer, "~NO_CARRIER"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -2) /* If input inactive... */
{
strcpy(buffer, "~NOT_ACTIVE"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -3) /* If time warning... */
{
strcpy(buffer, "~TIME_WARNING"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -4) /* If timeout... */
{
strcpy(buffer, "~TIMEOUT"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == 0x0d) /* If carriage return... */
{
buffer[count] = 0x00; /* ...flag end of string */
return(0); /* ...exit */
}
else if(key == 0x08) /* If backspace... */
{
if(count > 0) /* ...If buffer not empty... */
{
count--; /* ......adjust count */
print_char(8); /* ......backup */
}
}
else if(key >= 0x20) /* If printable character... */
{
if(count < max) /* ...If buffer not ful... */
{
buffer[count] = key; /* ......store character */
count++; /* ......adjust count */
print_char(key); /* ......and echo it */
}
}
}
}
/******************************************************************************
*
* TIO_INPUT - Input character
*
* process 1. Test carrier detect
* 2. Return -1 if carrier dropped
* 3. Test for no activity
* 4. Return -2 if no activity
* 5. Return -2 if no activity
* 6. Test for time limit exceeded
* 7. Return -3 if less than 2 minutes
* 8. Return -4 if time limit exceeded
* 9. Test for character ready
* 10. Goto 1 if no data available
* 11. Process local if local ready
* 12. Process remote if remote ready
* 13. Return character
* input none
* output Returns -1 if carrier dropped
* Returns -2 if no remote activity
* Returns -3 if less than 2 minutes remaining
* Returns -4 if no time remaining
* Returns chararcter
*****************************************************************************/
tio_input(ticks)
int ticks;
{
long cur_time(); /* Get current time decl */
long check_time; /* Cur time storage */
int stat; /* Input status variable */
mark_time = cur_time(); /* Flag current time */
if(ticks != 0)
{
mark_time2 = mark_time;
tick_time = mark_time + ticks; /* Flag timeout time */
}
while(1) /* Do until we get something */
{
if(modem_carrier()) /* If carrier dropped... */
return(-1); /* ...exit with error */
check_time = cur_time(); /* Check current time */
if(check_time < mark_time) /* If we wrapped past 12... */
check_time += DAY_SECONDS; /* ...adjust it */
if(check_time > (mark_time + 180L)) /* If it has been 3 mins... */
return(-2); /* ...exit with error */
stat = test_timeout(); /* Test remote time access */
if(stat == -1) /* If time warning msg... */
return(-3); /* ...exit with warning */
if(stat == -2) /* If time exceeded... */
return(-4); /* ...exit with error */
if(check_time < mark_time2) /* If we wrapped past 12... */
check_time += DAY_SECONDS; /* ...adjust it */
if(check_time > tick_time) /* If timer has expired... */
return(-5); /* ...exit with error */
stat = io_status(); /* Test if char available */
if(stat == 1) /* If keyboard char... */
return(local_input()); /* ...return it */
if(stat == 2) /* If remote char... */
{
stat = modem_input(); /* ...return it */
if(stat)
return(stat);
}
}
}
/******************************************************************************
*
* TIO_LINPUT - Timed input line with line feed
*
* process 1. Read a line
* 2. Print a crlf sequence
* 3. Return 0
* input Pointer to buffer
* output Returns 0
*****************************************************************************/
tio_linput(buffer, ticks)
char *buffer; /* Buffer to store input in */
int ticks; /* Time to wait */
{
tio_lxinput(buffer, ticks); /* Read a line */
print_string("\r\n"); /* Echo a new line */
return(0); /* Exit no error */
}
/******************************************************************************
*
* TIO_LXINPUT - Input line without line feed
*
* process 1. Read a character
* 2. If -1 return ~NO_CARRIER
* 3. If -2 return ~NOT_ACTIVE
* 4. If -3 return ~TIME_WARNING
* 5. If -4 return ~TIMEOUT
* 6. If -5 return ~TIMER
* 7. If cr then teminate input
* 8. If bs then print bs/space/bs
* 9. Ignore if buffer if full
* 10. Ignore if less than 20H and goto 1
* 11. Store character
* 12. Echo to output
* 12. Goto 1
* input Pointer to buffer
* output Returns 0
*****************************************************************************/
tio_lxinput(buffer, ticks)
char *buffer; /* Buffer to store chars in */
int ticks; /* Time to wait */
{
long cur_time(); /* Get current time decl */
int count = 0; /* Character counter */
int key; /* Character input variable */
int max = 80; /* Max buffer size */
mark_time2 = cur_time(); /* Flag current time */
tick_time = mark_time2 + ticks; /* Flag timeout time */
while(1) /* Repeat till done... */
{
key = tio_input(0); /* Get a character */
if(key == -1) /* If carrier dropped... */
{
strcpy(buffer, "~NO_CARRIER"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -2) /* If input inactive... */
{
strcpy(buffer, "~NOT_ACTIVE"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -3) /* If time warning... */
{
strcpy(buffer, "~TIME_WARNING"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -4) /* If timeout... */
{
strcpy(buffer, "~TIMEOUT"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -5) /* If timeout... */
{
strcpy(buffer, "~TIMER"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == 0x0d) /* If carriage return... */
{
buffer[count] = 0x00; /* ...flag end of string */
return(0); /* ...exit */
}
else if(key == 0x08) /* If backspace... */
{
if(count > 0) /* ...If buffer not empty... */
{
count--; /* ......adjust count */
print_char(8); /* ......backup */
}
}
else if(key >= 0x20) /* If printable character... */
{
if(count < max) /* ...If buffer not ful... */
{
buffer[count] = key; /* ......store character */
count++; /* ......adjust count */
print_char(key); /* ......and echo it */
}
}
}
}
/******************************************************************************
*
* IO_LEXINPUT - Input line without line feed or echo
*
* process 1. Read a caharcter
* 2. If -1 return ~NO_CARRIER
* 3. If -2 return ~NOT_ACTIVE
* 4. If -3 return ~TIME_WARNING
* 5. If -4 return ~TIMEOUT
* 6. If cr then teminate input
* 7. If bs then print bs/space/bs
* 8. Ignore if buffer if full
* 9. Ignore if less than 20H and goto 1
* 10. Store character
* 11. Echo to output
* 12. Goto 1
* input Pointer to buffer
* output Returns 0
*****************************************************************************/
io_lexinput(buffer)
char *buffer; /* Buffer to store chars in */
{
int count = 0; /* Character counter */
int key; /* Character input variable */
int max = 80; /* Max buffer size */
while(1) /* Repeat till done... */
{
key = io_input(); /* Get a character */
if(key == -1) /* If carrier dropped... */
{
strcpy(buffer, "~NO_CARRIER"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -2) /* If input inactive... */
{
strcpy(buffer, "~NOT_ACTIVE"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -3) /* If time warning... */
{
strcpy(buffer, "~TIME_WARNING"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == -4) /* If timeout... */
{
strcpy(buffer, "~TIMEOUT"); /* ...flag it */
return(0); /* ...exit */
}
else if(key == 0x0d) /* If carriage return... */
{
buffer[count] = 0x00; /* ...flag end of string */
return(0); /* ...exit */
}
else if(key == 0x08) /* If backspace... */
{
if(count > 0) /* ...If buffer not empty... */
{
count--; /* ......adjust count */
}
}
else if(key >= 0x20) /* If printable character... */
{
if(count < max) /* ...If buffer not ful... */
{
buffer[count] = key; /* ......store character */
count++; /* ......adjust count */
}
}
}
}
/******************************************************************************
*
* IO_PAUSE - Print an erasable prompt & wait for ENTER
*
* process 1. Print the message
* 2. Wait for enter
* 3. If -1 exit
* 4. If -2 exit
* 5. If -3 exit
* 6. If -4 exit
* 7. If no cr then goto 2
* 8. If remote is printing device exit
* 9. Erase message
* 10. Exit no errors
* input Pointer to message
* Centering flag (0 = left margin, 1 = center)
* output Returns 0
*****************************************************************************/
io_pause(message, center)
char *message; /* Message to print */
int center; /* Centering flag */
{
int count = 0; /* Character counter */
int key; /* Character input variable */
int i; /* Work variable */
/*
* Print the message
*/
if(center) /* If centering... */
count = (80 - strlen(message)) / 2; /* ...calc amount to indent */
for(i = 0 ; i < count ; i++) /* Indent desired amount */
print_char(' ');
/*
* Wait for ENTER
*/
while(1) /* Repeat till done... */
{
key = io_input(); /* Get a character */
if(key == -1) /* If carrier dropped... */
return(0); /* ...exit */
else if(key == -2) /* If input inactive... */
return(0); /* ...exit */
else if(key == -3) /* If time warning... */
return(0); /* ...exit */
else if(key == -4) /* If timeout... */
return(0); /* ...exit */
else if(key == 0x0d) /* If carriage return... */
{
if(user_nulls) /* If printing terminal... */
{
print_char('\r'); /* ...kick out a line */
print_char('\n');
}
else /* Otherwise... */
backup(count + strlen(message)); /* ...erase the message */
return(0); /* ...exit */
}
}
}
/******************************************************************************
*
* EOL_DISPLAY - Erase to End of Line
*
* process 1. If ANSI graphics then send sequence
* 2. Return 0
* input none
* output Returns 0
*****************************************************************************/
eol_display()
{
int i;
if(user_graphics == 2) /* If ANSI graphics... */
{
for(i = 0 ; i < strlen(eol) ; i++) /* ...print cls sequence */
print_char(eol[i]);
}
return(0); /* All done, no errors */
}
/******************************************************************************
*
* CLS_DISPLAY - Clear the display
*
* process 1. If ANSI graphics then send sequence
* 2. Else print line feeds
* 3. Return 0
* input none
* output Returns 0
*****************************************************************************/
cls_display()
{
int i;
if(user_graphics == 2) /* If ANSI graphics... */
{
for(i = 0 ; i < strlen(cls) ; i++) /* ...print cls sequence */
print_char(cls[i]);
local_line_no = 0; /* Reset line number */
put_local_banner(); /* Rewrite banner message */
set_local_cursor(0,0); /* Guarantee good position */
}
else /* Else use line feeds */
{
print_char('\r');
for(i = 0 ; i < 25 ; i++) /* Do 25 lines */
{
print_char('\n');
}
}
return(0); /* All done, no errors */
}
/******************************************************************************
*
* CLS2_DISPLAY - Clear the display
*
* process 1. If ANSI graphics then send sequence
* 2. Else print line feeds
* 3. Return 0
* input none
* output Returns 0
*****************************************************************************/
cls2_display()
{
int i;
if(user_graphics == 2) /* If ANSI graphics... */
{
for(i = 0 ; i < strlen(cls) ; i++) /* ...print cls sequence */
print_char(cls[i]);
local_line_no = 0; /* Reset line number */
put_local_banner(); /* Rewrite banner message */
set_local_cursor(0,0); /* Guarantee good position */
}
else /* Else use line feeds */
{
print_char('\r');
for(i = 0 ; i < 3 ; i++) /* Do 3 lines */
{
print_char('\n');
}
}
return(0); /* All done, no errors */
}
/******************************************************************************
*
* NO_CURSOR - Turn off local cursor
*
* process 1. Set cursor size via BIOS
* 2. Return 0
* input none
* output none
*****************************************************************************/
no_cursor()
{
union REGS inregs, outregs; /* Bios access structure */
struct SREGS segregs;
inregs.x.ax = (0x100); /* Bios function number */
inregs.h.ch = 32; /* Cursor start line */
inregs.h.cl = 32; /* Cursor end line */
int86x(0x10, &inregs, &outregs, &segregs); /* Do it */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* SMALL_CURSOR - Set a small local cursor
*
* process 1. Set cursor size via BIOS
* 2. Return 0
* input none
* output none
*****************************************************************************/
small_cursor()
{
union REGS inregs, outregs; /* Bios access structure */
struct SREGS segregs;
inregs.x.ax = (0x100); /* Bios function number */
inregs.h.ch = 6; /* Cursor start line */
inregs.h.cl = 7; /* Cursor end line */
int86x(0x10, &inregs, &outregs, &segregs); /* Do it */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* MEDIUM_CURSOR - Set a medium local cursor
*
* process 1. Set cursor size via BIOS
* 2. Return 0
* input none
* output none
*****************************************************************************/
medium_cursor()
{
union REGS inregs, outregs; /* Bios access structure */
struct SREGS segregs;
inregs.x.ax = (0x100); /* Bios function number */
inregs.h.ch = 3; /* Cursor start line */
inregs.h.cl = 7; /* Cursor end line */
int86x(0x10, &inregs, &outregs, &segregs); /* Do it */
return(0); /* Exit no errors */
}
/******************************************************************************
*
* LARGE_CURSOR - Set a large local cursor
*
* process 1. Set cursor size via BIOS
* 2. Return 0
* input none
* output none
*****************************************************************************/
large_cursor()
{
union REGS inregs, outregs; /* Bios access structure */
struct SREGS segregs;
inregs.x.ax = (0x100); /* Bios function number */
inregs.h.ch = 0; /* Cursor start line */
inregs.h.cl = 7; /* Cursor end line */
int86x(0x10, &inregs, &outregs, &segregs); /* Do it */
return(0); /* Exit no errors */
}
/*
*
* Position the Cursor
*
*/
position_cursor(x, y)
int x, y;
{
if(user_graphics == 2) /* Only support if ANSI */
{
print_string("\033[%d;%dH", y + 1, x + 1);
local_line_no = y;
return(0);
}
return(1); /* All done, no errors */
}
/*
*
* Print a Character
*
*/
print_char(data)
int data; /* Character to print */
{
print_charx(data); /* Print it */
if(data == 8) /* If it is a backspace... */
{
print_charx(' '); /* ...make it destructive */
print_charx(8);
}
return(0); /* No errors */
}
/*
*
* Print a Character
*
*/
print_charx(data)
int data; /* Character to print */
{
union REGS inregs, outregs;
int i, j;
if(user_caps && (data >= 'a') && (data <= 'z')) /* Adjust if case sensative */
j = data & 0x5f;
else
j = data;
local_output(j); /* Send to local console */
if(remote_user) /* If remote active... */
modem_output(j); /* ...he gets it too */
return(0); /* No errors */
}
/*
*
* Backup
*
*/
backup(count)
int count; /* Characters to backup */
{
int i;
for(i = 0 ; i < count ; i++)
print_char(8);
return(0); /* No errors */
}
/*
*
* Print a String
*
*/
print_string(string)
char *string; /* String to print */
{
va_list vlist;
int i;
va_start(vlist, string);
vsprintf(dmoutbuff, string, vlist);
va_end(vlist);
for(i = 0 ; i < strlen(dmoutbuff) ; i++)
print_char(dmoutbuff[i]);
return(0);
}
/*
*
* Metered Line Output
*
*/
print_metered(line, string, iobuff)
int *line; /* Pointer to line count */
char *string; /* Pointer to message */
char *iobuff; /* Pointer to buffer */
{
print_string(string); /* Print the message */
(*line)++; /* Bump line counter */
if(*line > (user_page - 2)) /* If at end of page... */
{
print_string(" Continue [Y], N, NS...");
io_lxinput(iobuff); /* ...wait for response */
backup(strlen(iobuff) + 52);
*line = 0; /* ...reset line count */
if(strcmp(strupr(iobuff), "\0") == 0) /* ...if continue... */
return(0); /* ......exit continue */
if(strcmp(strupr(iobuff), "Y") == 0) /* ...if continue... */
return(0); /* ......exit continue */
if(strcmp(strupr(iobuff), "NS") == 0) /* ...if continuous... */
return(1); /* ......exit continuous */
if(strcmp(strupr(iobuff), "N") == 0) /* ...if stop... */
return(2); /* ......exit stop */
else /* ...otherwise... */
return(-1); /* ......exit uncertain */
}
return(0); /* Exit continue */
}
/*
*
* Metered Line Output
* (no abort)
*
*/
print_meteredx(line, string, iobuff)
int *line; /* Pointer to line count */
char *string; /* Pointer to message */
char *iobuff; /* Pointer to buffer */
{
print_string(string); /* Print the message */
(*line)++; /* Bump line counter */
if(*line > (user_page - 2)) /* If at end of page... */
{
print_string(" Press [ENTER] to continue...");
io_lxinput(iobuff); /* ...wait for response */
backup(strlen(iobuff) + 55);
*line = 0; /* ...reset line count */
if(strcmp(strupr(iobuff), "\0") == 0) /* ...if continue... */
return(0); /* ......exit continue */
else /* ...otherwise... */
return(-1); /* ......exit uncertain */
}
return(0); /* Exit continue */
}
/******************************************************************************
*
* IO_WAIT - Wait for output to complete
*
* process 1. If local, exit
* 2. Wait for TX buffer empty
* 3. Exit
* input None
* output Returns AX = -1 if no carrier
* Returns AX = 0 if TX buffer empty
* Returns AX = 1 if timeout
*****************************************************************************/
io_wait()
{
/*
* Wait for complete
*/
local_wait(); /* Wait for complete */
return(modem_wait()); /* Wait for complete */
}
/******************************************************************************
*
* IO_IFLUSH - Purge all input
*
* process 1. Clear the buffers
* 2. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
io_iflush()
{
/*
* Flush buffers if in use
*/
local_iflush(); /* Flush local input */
modem_iflush(); /* Flush remote input */
return(0); /* Always returns 0 */
}
/******************************************************************************
*
* IO_OFLUSH - Purge all output
*
* process 1. Clear the buffers
* 2. Exit
* input None
* output Returns AX = 0
*****************************************************************************/
io_oflush()
{
/*
* Flush buffers
*/
local_oflush(); /* Flush local output */
modem_oflush(); /* Flush remote output */
return(0); /* Always returns 0 */
}
/* ************************************************************************* */
/* ************************ SUPPORT FUNCTIONS ************************** */
/* ************************************************************************* */
/* ********************* */
/* Read Port Info. */
/* ********************* */
dmread_ports()
{
char *fgets(); /* Get string function */
FS cfg; /* Config file structure */
char parms[7][41]; /* Config parameters */
int not_done; /* Loop control */
int commid; /* Comm Port ID being defined */
int portid; /* Comm Port address */
int irqid; /* IRQ number */
int intid; /* Interrupt flag */
int handid; /* Handshake flag */
int passid; /* Passthrough flag */
int levels; /* Levels defined */
int i, j, k; /* Work variables */
/*
* Open up the config file
*/
strcpy(cfg.name, bbs_dir); /* Build filename */
strcat(cfg.name, "PORTS.BBS"); /* Open node file */
i = file_open(&cfg, FREAD, FTEXT, FNOCREATE); /* Open node file */
if(i) /* If file not there... */
return(0); /* ...then use defaults */
/*
* Process the file
*/
not_done = 1;
levels = 0;
while(not_done)
{
/*
* Read in the record
*/
if(fgets(dminbuff, 128, cfg.fd) == 0L)
not_done = 0;
else if(dminbuff[0] == 0x1a)
not_done = 0;
else if(dminbuff[0] != ';')
{
i = 0;
k = 0;
while((k < 7) &&
(dminbuff[i] != 0x0d) && (dminbuff[i] != 0x0a) &&
(dminbuff[i] != 0x00) && (dminbuff[i] != 0x1a))
{
while((dminbuff[i] == ' ') || (dminbuff[i] == 0x09))
i++;
j = 0;
while((dminbuff[i] != ' ') && (dminbuff[i] != 0x09) &&
(dminbuff[i] != 0x0d) && (dminbuff[i] != 0x0a) &&
(dminbuff[i] != 0x00) && (dminbuff[i] != 0x1a))
{
parms[k][j] = dminbuff[i];
j++;
i++;
}
parms[k][j] = '\0';
k++;
}
if(k == 0)
{
/* Ignore blank lines */
}
else if(parms[0][0] == ';')
{
/* Skip comment line */
}
else if((k == 6) || ((k == 7) && (parms[6][0] == ';')))
{
commid = get_commid(parms[0]);
if((commid < 1) || (commid > 8))
{
file_close(&cfg);
return(-3); /* Bad comm port parameter */
}
portid = get_portid(parms[1]);
if(portid == -1)
{
file_close(&cfg);
return(-4); /* Bad comm port address */
}
irqid = get_irqid(parms[2]);
if(irqid == -1)
{
file_close(&cfg);
return(-5); /* Bad IRQ number */
}
intid = get_intid(parms[3]);
if(intid == -1)
{
file_close(&cfg);
return(-6); /* Bad interrupt enable flag */
}
handid = get_handid(parms[4]);
if(handid == -1)
{
file_close(&cfg);
return(-7); /* Bad handshaking flag */
}
passid = get_yesno(parms[5]);
if(passid == -1)
{
file_close(&cfg);
return(-8); /* Bad passthrough flag */
}
if(dmio_ports[commid - 1].defined == 2)
{
file_close(&cfg);
return(-9); /* Duplicate port definition */
}
else /* else store the definitions */
{
dmio_ports[commid - 1].defined = 2;
dmio_ports[commid - 1].address = portid;
dmio_ports[commid - 1].irq_id = irqid;
dmio_ports[commid - 1].int_enable = intid;
dmio_ports[commid - 1].handshake = handid;
dmio_ports[commid - 1].passthru = passid;
levels++;
}
}
else
{
file_close(&cfg);
return(-2); /* Illegal number of parameters */
}
}
}
file_close(&cfg);
if(levels)
return(0); /* config file read ok */
else
return(-10); /* No defined comm ports in file */
}
/* ********************* */
/* Convert Comm ID */
/* ********************* */
get_commid(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Make sure it is COMx
*/
if(strlen(string) != 4) /* Must be 4 chars long */
return(0);
if(strnicmp(string, "COM", 3) != 0) /* Must be in COMx format */
return(0);
/*
* Get port ID and range check it
*/
value = atoi(&string[3]); /* Get port id */
if((value < 1) || (value > 8)) /* Range check it */
return(0);
else
return(value);
}
/* ********************* */
/* Convert Comm Addr */
/* ********************* */
get_portid(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Parse out & validate port number
*/
if(strlen(string) > 4) /* Must be 4 chars long or less */
return(-1);
/*
* Get port address
*/
value = 0; /* Init the value */
for(i = 0 ; i < strlen(string) ; i++)
{
switch(string[i])
{
case '0': /* Digit value 0 */
value *= 16;
value += 0;
break;
case '1': /* Digit value 1 */
value *= 16;
value += 1;
break;
case '2': /* Digit value 2 */
value *= 16;
value += 2;
break;
case '3': /* Digit value 3 */
value *= 16;
value += 3;
break;
case '4': /* Digit value 4 */
value *= 16;
value += 4;
break;
case '5': /* Digit value 5 */
value *= 16;
value += 5;
break;
case '6': /* Digit value 6 */
value *= 16;
value += 6;
break;
case '7': /* Digit value 7 */
value *= 16;
value += 7;
break;
case '8': /* Digit value 8 */
value *= 16;
value += 8;
break;
case '9': /* Digit value 9 */
value *= 16;
value += 9;
break;
case 'a': /* Digit value A */
case 'A':
value *= 16;
value += 10;
break;
case 'b': /* Digit value B */
case 'B':
value *= 16;
value += 11;
break;
case 'c': /* Digit value C */
case 'C':
value *= 16;
value += 12;
break;
case 'd': /* Digit value D */
case 'D':
value *= 16;
value += 13;
break;
case 'e': /* Digit value E */
case 'E':
value *= 16;
value += 14;
break;
case 'f': /* Digit value F */
case 'F':
value *= 16;
value += 15;
break;
default: /* Bad digit */
return(-1);
}
}
return(value);
}
/* ********************* */
/* Convert IRQ ID */
/* ********************* */
get_irqid(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Make sure it is IRQx
*/
if(strlen(string) != 4) /* Must be 4 chars long */
return(-1);
if(strnicmp(string, "IRQ", 3) != 0) /* Must be in IRQx format */
return(-1);
/*
* Get port ID and range check it
*/
value = atoi(&string[3]); /* Get IRQ number */
if((value < 0) || (value > 7)) /* Range check it */
return(-1);
else
return(value);
}
/* ********************* */
/* Convert YES/NO */
/* ********************* */
get_yesno(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Get YES/NO answer
*/
if(strcmpi(string, "YES") == 0) /* Test for YES parameter */
return(1);
else if(strcmpi(string, "NO") == 0) /* Test for NO parameter */
return(0);
else /* otherwise is bad */
return(-1);
}
/* ********************* */
/* Convert Access Type */
/* ********************* */
get_intid(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Get access parameter
*/
if(strcmpi(string, "BIOS") == 0) /* Test for BIOS/Fossil access */
return(0);
else if(strcmpi(string, "PORT") == 0)/* Test for Direct port access */
return(1);
else if(strcmpi(string, "INTR") == 0)/* Test for Interrupt driven access */
return(2);
else /* otherwise is bad */
return(-1);
}
/* ********************* */
/* Convert Handshake */
/* ********************* */
get_handid(string)
char *string;
{
int value; /* return value */
int i; /* string index */
/*
* Get handshake parameter
*/
if(strcmpi(string, "NONE") == 0) /* Test for NONE parameter */
return(0);
else if(strcmpi(string, "SOFT") == 0)/* Test for SOFT parameter */
return(1);
else if(strcmpi(string, "HARD") == 0)/* Test for HARD parameter */
return(2);
else if(strcmpi(string, "BOTH") == 0)/* Test for BOTH parameter */
return(3);
else /* otherwise is bad */
return(-1);
}